home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / DELBUF.MUT < prev    next >
Text File  |  1992-11-09  |  1KB  |  41 lines

  1.    ;; delbuf.mut : Dispose of a buffer, by name.
  2.    ;; Default is current buffer.
  3.    ;; If a window is displaying the buffer to be deleted, delete that
  4.    ;;   window.
  5.    ;; C Durland        Public Domain
  6.  
  7. (include me2.h)
  8.  
  9. (defun
  10.   MAIN { (bind-to-key "delete-buffer" "C-xk") }
  11.   delete-buffer
  12.   {
  13.     (string name)(int j n buf-id)
  14.  
  15.     (name (complete CC_BUF "Delete buffer: "))
  16.     (if (== name "") (buf-id (current-buffer))    ;; use the default 
  17.       (if (== -2 (buf-id (attached-buffer name)))
  18.     { (msg '"' name '" is not a buffer.')(done) }))
  19.  
  20.         ;; Ask before we delete a modified buffer we care about
  21.     (if (and
  22.           (== BFModified    ;; Check to see if we care about this buffer
  23.           (bit-and (buffer-flags buf-id) (bit-or BFModified BFNoCare)))
  24.           (not (yesno (buffer-name buf-id) " has changed.  Delete anyway")))
  25.        (done))            ;; They don't want to delete it
  26.  
  27.     (if (arg-flag)
  28.       {
  29.         ;; remove all windows displaying buffer to be deleted
  30.         ;; (unless its the only one left).
  31.     (n 0)
  32.     (while (and (< n (windows))(> (windows) 1))
  33.     {
  34.       (if (== buf-id (attached-buffer n)) { (free-window n) (continue) } )
  35.       (+= n 1)
  36.     })
  37.       })
  38.     (free-buffer buf-id)            ;; Kiss that sucka goodbye
  39.   }
  40. )
  41.